<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;

class Node extends AdminController
{
	public function index()
	{
		$query = Db::field('*')
			->name('node')
			->select();
			return view('admin@node/index', ['data' => $query]);
	}


	public function add()
	{
		return view('admin@node/add');
	}


	public function edit($id)
	{
		$data = Db::name('node')->where('id', $id)->find();
		// var_dump($data);

		$this->assign('data', $data);
		return view();
	}


	public function save()
	{
		$data = (input('post.'));
		// dump($data);
		Db::name('node')->where('id', input('post.id'))->update($data);
		$this->success('修改成功', 'admin/Node/index');
	}


	public function doAdd()
	{
		// var_dump(input('post.'));
		Db::name('node')->insert(input('post.'));
		$this->success('添加成功', 'admin/node/index');
	}


	public function dodel()
	{
		$id = input('get.id');
		// dump($rid);
		$role = Db::name('node')->where('id', $id)->delete();
		if($role) {
			$this->success('删除成功', 'admin/node/index');
		} else {
			$this->error('删除失败');
		}
	}
}
